{extend name="index/iframe" /}

{block name="content"}
<form class="layui-form layui-form-my" action="">
    <input type="hidden" value="{$Think.get.id}" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">父级分类</label>
        <div class="layui-input-block">
            <select name="pid" id="pid" lay-filter="pid" lay-search="" disabled class="layui-disabled">
                {volist name="$faq_list" id="vo"}
                <option value="{$vo.id}-{$vo.rid}" {$find.pid==$vo.id ? 'selected' : ''}>{:str_repeat($vo['html'], $vo['rid'])}{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="{$find.title}" id="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">提问</label>
        <div class="layui-input-block">
            <input type="text" name="question" value="{$find.question}" id="question" placeholder="请输入提问" autocomplete="off" class="layui-input layui-disabled" disabled>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">答案</label>
        <div class="layui-input-block">
            <textarea name="answer" id="answer" placeholder="请输入答案" class="layui-textarea layui-disabled" disabled>{$find.answer}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use(['form'], function(){
        var form = layui.form
            ,$ = layui.$
            ,layer = layui.layer;

        if({$find.rid}==3){ //验证等级
            $('#title').addClass('layui-disabled').attr('disabled', true);
            $('#question').removeClass('layui-disabled').attr('disabled', false);
            $('#answer').removeClass('layui-disabled').attr('disabled', false);
        }else{
            $('#title').removeClass('layui-disabled').attr('disabled', false);
            $('#question').addClass('layui-disabled').attr('disabled', true);
            $('#answer').addClass('layui-disabled').attr('disabled', true);
        }
        form.render();

        //提交
        form.on('submit(submitBtn)', function(data){
            var load = layer.load()
                ,d = data.field.pid
                ,id = d.split("-");
            data.field.pid = id[0];
            data.field.rid = id[1];

            $.post('{:url("Faq/edit")}', data.field, function(json){
                layer.close(load);
                if(json.code==0){
                    layer.msg(json.msg, {icon: 1, time: 1000});
                }else{
                    layer.msg(json.msg, {icon: 0, time: 1000});
                }
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
            return false;
        });
    });
</script>
{/block}